#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
This example demonstrates how to veto an event

example from www.zetcode.com
"""

import wx

class Example(wx.Frame):

    def __init__(self, *args, **kwds):
        super(Example, self).__init__(*args, **kwds)

        self.InitUI()

    def InitUI(self):
        
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
        
        self.SetTitle('Event veto')
        self.Center()
        self.Show(True)

    def OnCloseWindow(self, e):
        popup = wx.MessageDialog(None, 'Are you sure you want to quit?', 'Question',
                                 wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
        ret= popup.ShowModal()
        
        if ret == wx.ID_YES:
            self.Destroy()
        else:
            e.Veto()


def main():
    ex = wx.App()
    Example(None)
    ex.MainLoop()

if __name__ == '__main__':
    main()
